<%-- 
    Document   : index
    Created on : Oct 8, 2014, 10:20:09 PM
    Author     : DucND
--%>

<%@page import="java.sql.SQLException"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page import="dao.ManagerDAO"%>
<%@page import="entity.Manager"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%! String username;
    String password;
    String loginBtn;
    String msg;
%>
<%
    request.getSession().removeAttribute("Username");
    msg = "";
    loginBtn = request.getParameter("loginBtn");
    if (loginBtn != null) {
       username = request.getParameter("username");
       password = request.getParameter("password");
       if (username.equals(ManagerDAO.login(username, password))) {
           request.getSession().setAttribute("Username", username);
           response.sendRedirect("index.jsp");
       } else {
           msg = "Wrong Username/Password";
       }
    }
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">


<!DOCTYPE html>
<html lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        <title>Login</title>

        <!-- Bootstrap core CSS -->
        <link type="text/css" href="../css/bootstrap.css" rel="stylesheet">

        <!-- Custom styles for this template -->
        <link href="../css/login.css" rel="stylesheet">
    </head>

    <body>

        <div class="container">

            <form class="form-login" action="login.jsp" method="POST">
                <h2 id="h2" class="form-login-heading">Please log in</h2>
                <br>
                <input type="text" name="username" class="form-control" placeholder="Username" autofocus required>
                <input type="password" name="password" class="form-control" placeholder="Password" required>
                <br><font color="red"><%=msg%></font><br>
                <button name="loginBtn" class="btn btn-lg btn-primary btn-block" type="submit">Log in</button>
            </form>
        </div> <!-- /container -->
        <!-- Button trigger modal -->
        <div align="center">
            <form action="forgotPassword.jsp" method="POST">
                <button class="btn btn-link" type="submit">
                    Forgot your password?
                </button>
            </form>
        </div>
    </body>
</html>